/**
 * Copyright (c) 2013 An Yaming,  All Rights Reserved
 */
package so.shanku.essential.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.tsz.afinal.json.JsonMap;
import so.shanku.essential.R;

import java.util.List;


/** 
* @ClassName: ShoppingUserRecipientAdapter 
* @Description: TODO(某个控件包含单击事件的数据适配器) 
* @author tanghuan
* @date 2014年12月3日 下午8:02:30 
*   
*/ 
public class ShoppingUserRecipientAdapter extends HasClickAdapter {
	/**
	 * 选中的id
	 */
	private int selectPosition;

	public int getSelectPosition() {
		selectPosition = -1;
		for (int sdw = 0; sdw < datas.size(); sdw++) {
            JsonMap jsonMap= (JsonMap) datas.get(sdw);
			if (jsonMap.getBoolean("isSelect")) {
				selectPosition = sdw;
			}
		}
		return selectPosition;
	}

	// 调用适配器的传参
	private int defaultImgResource;

	public ShoppingUserRecipientAdapter(Context context,
	                                    List<JsonMap<String, Object>> data, int resource, String[] from,
	                                    int[] to, int defaultImgResource, int resId,
	                                    ItemOneViewClickListener clickListener) {
		super(context,data);
		this.defaultImgResource = defaultImgResource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
        JsonMap jsonMap= (JsonMap) datas.get(position);
		View v = super.getView(position, convertView, parent);
		ImageView iv = (ImageView) v.findViewById(R.id.i_s_u_r_i_ib_chooice);
		//LinearLayout ll_chooose = (LinearLayout) v.findViewById(R.id.i_s_u_r_i_ll_chooice);
		TextView name = (TextView) v.findViewById(R.id.i_s_u_r_i_tv_recipient_name);
		if (jsonMap.getBoolean("isDefault")) {
			name.setTextColor(name.getResources().getColor(R.color.textcolorred1));
		}else{
			name.setTextColor(name.getResources().getColor(R.color.TextColorBlack));
		}
		if (1 == defaultImgResource) {
			iv.setVisibility(View.GONE);
		} else {
			if (null != iv) {
//				if (data.get(position).getBoolean("isSelect")) {
//					iv.setImageResource(R.drawable.shopping_select_all);
//				} else {
//					iv.setImageResource(R.drawable.shopping_select_noall);
//				}
				iv.setSelected(jsonMap.getBoolean("isSelect"));
			}
		}

		return v;
	}

}
